<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$return['ischecklogin']=cfc('core')->checklogin('','',true);
	$return['list']=array();
	$return['params']=array(
		'plugin_name'=>'jy_weishop',
	);
	set_html('title',$return['setting']['torder']?:'进货订单');
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	if($_RQ['plugin_name']){
		$params['plugin_name']=$_RQ['plugin_name'];
	}
	$psize=20;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->get_list('order',$parameter);
	if(!$list){
		exi('none');
	}
	foreach($list as &$item){		
		$item['member']=model('core/member')->basic($item['mid']);
		$goods=array();
		if($item['plugin_name']=='jy_weishop'){
			$orderid=pdo_getcolumn('jy_weishop_order',array('ordersn'=>$item['ordersn'],'uniacid'=>$_SESSION['uniacid']),'id');
			$ordergoods=pdo_getall('jy_weishop_order_goods',array('orderid'=>$orderid,'uniacid'=>$_SESSION['uniacid']),array('goodsid','optionid','price','total','goodssn','productsn'));
			foreach($ordergoods as &$gv){
				$goodsinfo = pdo_get('jy_weishop_goods',array('id'=>$gv['goodsid'],'uniacid'=>$_SESSION['uniacid']),array('id','marketprice','unit','image','title','merchid'));
				$goodsinfo['total']=$gv['total'];
				$goodsinfo['price']=$gv['price'];
				if($_SESSION['is_tomedia']){
				$goodsinfo['image']=$goodsinfo['image']?tomedia($goodsinfo['image']):'';
				}
				$goodsinfo['weight']=pdo_getcolumn('jy_weishop_goods_dispatch',array('goodsid'=>$gv['goodsid']),'weight');
				if($feemoneyset['isopen']==1){
					$gv['feemoney']=$goodsinfo['marketprice']>0?$goodsinfo['marketprice']-$item['price']:$feemoneyset['feerade']*$item['price']/100;
					$gv['feemoney']=$gv['total']*$gv['feemoney'];
					$item['feemoney'] +=$gv['feemoney'];
					$goodsinfo['feemoney']=price($gv['feemoney']);
				}
				//获取门店
				$stores = array();
				$goodsinfo['storeids'] = json_decode($goodsinfo['storeids'],true);
				if ($goodsinfo['isverify'] == 1) {
					if (empty($goodsinfo['storeids'])) {
						$stores = pdo_getall('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'type'=>array(2,3)));
					}else {
						foreach($goodsinfo['storeids'] as $sv){
							$stores[]= pdo_get('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'type'=>array(2,3),'id'=>$sv['id']));
						}
					}
				}elseif($shopset['openstore'] ==1){
					if (empty($goodsinfo['storeids'])) {
						$stores = pdo_getall('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'status'=>1));
					}else {
						foreach($goodsinfo['storeids'] as $sv){
							$stores[]= pdo_get('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'id'=>$sv['id']));
						}
					}
				}
				$goodsinfo['store']=$stores;
				//商品规格
				if($gv['optionid']){
					$specs=pdo_getcolumn('jy_weishop_goods_option',array('id'=>$gv['optionid']),'specs');
					$specs=explode("_",$specs);
					foreach($specs as &$spec){
						$spec=pdo_getcolumn('jy_weishop_goods_spec_item',array('id'=>$spec),'title');
					}
					$goodsinfo['selespename']=implode("，",$specs);
				}
				$goods[] = $goodsinfo;
			}
		}elseif($item['plugin_name']=='jy_onlineedu'){
			$video_id=pdo_getcolumn('jy_onlineedu_video_order',array('ordersn'=>$item['ordersn'],'uniacid'=>$_SESSION['uniacid']),'video_id');
			$video=pdo_get('jy_onlineedu_video',array('id'=>$video_id,'uniacid'=>$_SESSION['uniacid']));
			$goods[] = $video;
		}
		$item['goods']=$goods;
	}
	exi($list);
}
?>